﻿/*
 * Created by SharpDevelop.
 * User: rogerio
 * Date: 25/02/2010
 * Time: 10:11
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;

namespace csharp.rad.finan
{
	/// <summary>
	/// Description of payment.
	/// </summary>
	public class Payment : common.DefaultClass, common.IClass
	{
		#region private declarations
			private string _payment_bpr_detail_id;
			private string _payment_user_id;
			private string _payment_date;
			private string _payment_value;
			private string _payment_juros_value;
			private string _payment_penalty_value;
			private string _payment_discount_value;
			private string _payment_paid_value;
			private string _payment_obs;
  			private string _payment_pay_day;
		#endregion
	    		
	    #region properties
			public string bpr_detail_id {
				get { return _payment_bpr_detail_id; }
				set { _payment_bpr_detail_id = value; }
			}
			
			public string user_id {
				get { return _payment_user_id; }
				set { _payment_user_id = value; }
			}
			
			public string date {
				get { return _payment_date; }
				set { _payment_date = value; }
			}
			
			public string value {
				get { return _payment_value; }
				set { _payment_value = value; }
			}
			
			public string juros_value {
				get { return _payment_juros_value; }
				set { _payment_juros_value = value; }
			}
			
			public string penalty_value {
				get { return _payment_penalty_value; }
				set { _payment_penalty_value = value; }
			}
			
			public string discount_value {
				get { return _payment_discount_value; }
				set { _payment_discount_value = value; }
			}
			
			public string paid_value {
				get { return _payment_paid_value; }
				set { _payment_paid_value = value; }
			}
			
			public string obs {
	    	get { return _payment_obs; }
				set { _payment_obs = value; }
			}
			
			public string pay_day {
				get { return _payment_pay_day; }
				set { _payment_pay_day = value; }
			}
		#endregion
		
		public Payment()
		{
			gsql.table = "finan.payment";
			_sequence  = "finan.payment_payment_id_seq";  
		}
		
		public override void get(System.Data.DataRow dr)
		{
			_id 						= dr["payment_id"].ToString();
			_payment_bpr_detail_id   	= dr["payment_bpr_detail_id"].ToString();
			_payment_user_id			= dr["payment_user_id"].ToString();
			_payment_date				= dr["payment_date"].ToString();
			_payment_value				= dr["payment_value"].ToString();
			_payment_juros_value		= dr["payment_juros_value"].ToString();
			_payment_penalty_value 		= dr["payment_penalty_value"].ToString();
			_payment_discount_value  	= dr["payment_discount_value"].ToString();
			_payment_paid_value			= dr["payment_paid_value"].ToString();
			_payment_obs				= dr["payment_obs"].ToString();
			_payment_pay_day			= dr["payment_pay_day"].ToString();
		}
			
		public override void setGsql()
		{			
			gsql.setValue( _id,      	 				"payment_id");
			gsql.setValue( _payment_bpr_detail_id,  	"payment_bpr_detail_id");
			gsql.setValue( _payment_user_id,			"payment_user_id");
			gsql.setAsDateTime( _payment_date,			"payment_date");
			gsql.setAsDouble( _payment_juros_value,		"payment_juros_value");
			gsql.setAsDouble( _payment_value,			"payment_value");
			gsql.setAsDouble( _payment_penalty_value, 	"payment_penalty_value");
			gsql.setAsDouble( _payment_discount_value, 	"payment_discount_value");
			gsql.setAsDouble( _payment_paid_value,		"payment_paid_value");
			gsql.setValue( _payment_obs,				"payment_obs");
			gsql.setAsDateTime( _payment_pay_day,		"payment_pay_day");
		}
		
		public void clear()
		{
			_id 			 			= string.Empty;
			_payment_bpr_detail_id 		= string.Empty;
  			_payment_user_id			= string.Empty;
  			_payment_date				= string.Empty;
  			_payment_value				= string.Empty;	
  			_payment_juros_value		= string.Empty;
  			_payment_penalty_value		= string.Empty;
  			_payment_discount_value		= string.Empty;
  			_payment_paid_value			= string.Empty;
  			_payment_obs				= string.Empty;
  			_payment_pay_day			= string.Empty;
		}
	}
	
	public class Payments : common.DefaultList, common.IList
	{
		public Payments()
		{
			gsql.table = "finan.payment";
		}
		
		public Payment get(Int32 index)
		{
			return (Payment)items[index];
		}
		
		public Payment get()
		{
			return (Payment)items[index];
		}
		
		public bool fillList()
		{
			gsql.prepare();
			gsql.setValue("","*");
			
			return mountList();
		}
		
		public bool searchByBprDetail(string bpr_detail_id)
		{
			gsql.prepare();
			gsql.setValue("","*");
			gsql.conditionalWhere= "payment_bpr_detail_id = "+bpr_detail_id;
			
			if(!mountList())
				return false;
			
			if( items.Count <= 0 )
				return false;
			return true;
		}
		
		private bool mountList()
		{
			Int32 tam;
			
			if (!gsql.execute())
				return false;
			
			tam = gsql.getRowCount();
			items.Clear();
			for (int i=0; i < tam; i++)
			{
				Payment aux = new Payment();
				aux.get(gsql.getRow(i));
				items.Add(aux);
			}
			return true;
		}
	}
}
